import Router from '@koa/router';
import { addDoc, getDocs, getDatabase } from '../controllers/home';

export const router = new Router();

router.get('/getDatabase', (ctx) => {
  const { db } = ctx.query;
  ctx.body = getDatabase(db);
});

router.get('/getDocs', async (ctx) => {
  const { db, collection } = ctx.query;
  ctx.body = await getDocs(db, collection);
});

router.post('/addDoc', (ctx) => {
  const { db, collection, doc } = ctx.request.body;
  if (db && collection && doc) {
    ctx.body = addDoc(db, collection, doc);
  }
});

export default router;
